import 'package:elevator_app/components/exit_prompt/exit_prompt.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../components/appbar_widget/appbar_widget.dart';
import '../../components/loading/text_loading.dart';
import '../../components/status/not_network.dart';
import '../../components/status/toast.dart';
import '../../config/global_config.dart';
import '../../utils/screenutil/fit.dart';
import 'bean/login_info.dart';
import 'components/android_text_field.dart';
import 'components/base_checkbox.dart';
import 'ctrl/login_ctrl.dart';

class Login extends StatelessWidget {
  // 导入控制器
  final loginCtrl = Get.put(LoginCtrl());

  //
  // static TextEditingController account = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: AppBarWidget("登录", isMore: false).build(context),
      body: ExitPrompt(
        child: Obx(
          () => loginCtrl.initComplete.value
              ? GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
                  child: Container(
                    alignment: Alignment.topCenter,
                    child: Container(
                      width: 640.f,
                      height: double.infinity,
                      alignment: Alignment.center,
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children: [
                          // 无网络提示
                          NotNetwork(),

                          // logo信息
                          Logo("快点云"),

                          // 输入框
                          Container(
                            margin: EdgeInsets.symmetric(horizontal: 30.f),
                            decoration: BoxDecoration(color: Colors.white),
                            child: AndroidTextField(
                              loginCtrl.readLoginInfoCache(),
                              isEmptyPWD: loginCtrl.isEmptyPWD.value,
                            ),
                          ),

                          // 复选框
                          Container(
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              crossAxisAlignment: CrossAxisAlignment.end,
                              children: [
                                Container(
                                  alignment: Alignment.centerLeft,
                                  margin:
                                      EdgeInsets.only(top: 20.f, left: 30.f),
                                  child: BaseCheckbox(
                                    checkedStatus: loginCtrl.rememePwd.value,
                                    onChanged: (bool val) =>
                                        loginCtrl.rememePwd.value = val,
                                  ),
                                ),
                                Padding(
                                  padding: EdgeInsets.only(
                                    bottom: 10.f,
                                    right: 30.f,
                                  ),
                                  child: InkWell(
//                                  onTap: () => Get.toNamed(AppRoutes.ForgotPWD),
                                    onTap: () => null,
                                    child: Text(
                                      "",
                                      style:
                                          TextStyle(color: GlobalConfig.theme),
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),

                          // 登录按钮
                          Container(
                            width: 580.f,
                            margin: EdgeInsets.only(top: 40.f),
                            decoration: BoxDecoration(
                              color: GlobalConfig.theme,
                              borderRadius: BorderRadius.circular(10.f),
                            ),
                            child: FlatButton(
                              onPressed: () {
                                LoginInfoBean _result =
                                    AndroidTextField.verificaResult();
                                if (_result.status) {
                                  // 执行登录
                                  loginCtrl.login(_result.data);
                                } else {
                                  Toast.toast(title: _result.msg);
                                }
                              },
                              child: Text(
                                "登录",
                                style: TextStyle(color: Colors.white),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                )
              : TextLoading(),
        ),
      ),
    );
  }

  /// logo图标
  Widget Logo(String name) {
    return Container(
      margin: EdgeInsets.only(top: 120.f, bottom: 50.f),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Container(
            margin: EdgeInsets.only(right: 20.f),
            child: Image.asset(
              "assets/images/logo.png",
              width: 300.f,
            ),
          ),
        ],
      ),
    );
  }
}
